<?php
namespace app\farm\controller;
use app\AdminRest;
use app\ApiRest;

use app\farm\model\Address;
use app\farm\model\BalanceWater;
use app\farm\model\Claim;
use app\farm\model\ClaimOrder;
use app\farm\model\Config;
use app\farm\model\Evaluate;
use app\farm\model\FinanceWater;
use app\farm\model\LandCate;
use app\farm\model\Farmer;

use app\farm\model\LandCycle;
use app\farm\model\LandList;
use app\farm\model\LandMassif;
use app\farm\model\LandOrder;
use app\farm\model\LandOrderSeed;
use app\farm\model\LandSeed;
use app\farm\model\LandSpe;
use app\farm\model\LandText;
use app\farm\model\Massif;
use app\farm\model\OrderAddress;
use app\farm\model\Seed;
use app\farm\model\SendOrder;
use app\farm\model\Source;
use app\massage\controller\IndexWxPay;
use app\farm\model\User;
use app\shop\model\FreightTemplate;
use think\App;
use think\facade\Db;
use think\Request;


class AdminLand extends AdminRest
{

    protected $model;

    protected $cate_model;


    public function __construct(App $app) {

        parent::__construct($app);

        $this->model = new LandList();

        $this->cate_model = new LandCate();

    }






    /**
     * @author chenniang
     * @DataTime: 2021-12-14 17:42
     * @功能说明:认养分类列表
     */
    public function landCateList(){

        $input = $this->_param;

        $cate_model = new LandCate();

        $dis = [

            'type'    => 1,

            'uniacid' => $this->_uniacid,

            'status'  => 1,

        ];

        $data = $cate_model->where($dis)->order('top desc,id desc')->select()->toArray();

        return $this->success($data);

    }


//    /**
//     * @author chenniang
//     * @DataTime: 2021-12-14 17:53
//     * @功能说明:土地列表
//     */
//    public function landList(){
//
//        $input = $this->_param;
//
//        $input['sort'] = !empty($input['sort'])?$input['sort']:1;
//
//        $dis[] = ['uniacid','=',$this->_uniacid];
//
//        $dis[] = ['status','=',1];
//
//        if(!empty($input['cate_id'])){
//
//            $dis[] = ['cate_id','=',$input['cate_id']];
//        }
//
//        if(!empty($input['title'])){
//
//            $dis[] = ['title','like','%'.$input['title'].'%'];
//
//        }
//
//        if(!empty($input['farmer_id'])){
//
//            $dis[] = ['farmer_id','=',$input['farmer_id']];
//        }
//
//        $lat = !empty($input['lat'])?$input['lat']:0;
//
//        $lng = !empty($input['lng'])?$input['lng']:0;
//
//        $alh = '(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*('.$lng.'- `lng`)/360),2)+COS(PI()*33.07078170776367/180)* COS('.$lat.' * PI()/180)*POW(SIN(PI()*('.$lat.'- lat)/360),2))))*1000 as distance';
//
//        $data = $this->model->indexDataList($dis,$alh,$input['sort']);
//
//        return $this->success($data);
//
//    }


//    /**
//     * @author chenniang
//     * @DataTime: 2021-12-16 10:34
//     * @功能说明:土地详情
//     */
//    public function landInfo(){
//
//        $input = $this->_param;
//
//        $dis = [
//
//            'id' => $input['id']
//        ];
//
//        $data = $this->model->landInfo($dis);
//
//        $farmer_model = new Farmer();
//        //农场主消息
//        $data['farmer_info'] = $farmer_model->dataInfo(['id'=>$data['farmer_id']],'mobile,title,cover');
//
//        $app_num = 0;
//
//        if(!empty($data['spe'])){
//
//            $order_model = new LandOrder();
//
//            foreach ($data['spe'] as &$v){
//
//                $dis = [
//
//                    'land_id' => $input['id'],
//
//                    'spe_id'  => $v['id']
//                ];
//
//                $v['is_app'] = $order_model->where($dis)->where('pay_type','>',1)->find();
//
//                $v['is_app'] = !empty($v['is_app'])?1:0;
//
//                if($v['is_app']==1){
//
//                    $app_num ++;
//                }
//
//            }
//
//        }
//
//        $data['spe_info'] = [
//            //总数量
//            'all_num' => count($data['spe']),
//            //已被预约数量
//            'app_num' => $app_num
//
//        ];
//
//        return $this->success($data);
//
//    }


    /**
     * @author chenniang
     * @DataTime: 2022-02-11 11:24
     * @功能说明:土地预支付信息
     */
    public function landPayOrderInfo(){

        $input = $this->_input;

        $order_model  = new LandOrder();

        $farmer_model = new Farmer();

        $data = $order_model->payOrderInfo($input);

        if(!empty($data['code'])){

            $this->errorMsg($data['msg']);
        }

        $data['farmer_info'] = $farmer_model->dataInfo(['id'=>$data['land']['farmer_id']],'title');

        $address_model  = new OrderAddress();
        //地址
        $data['address']= $address_model->dataInfo(['id'=>$input['address_id']]);

        return $this->success($data);
    }



    /**
     * @author chenniang
     * @DataTime: 2021-12-16 10:57
     * @功能说明:土地下单
     */
    public function landPayOrder(){

        $input = $this->_input;

        $address_model  = new OrderAddress();

        $order_model    = new LandOrder();

        $land_seed_model= new LandOrderSeed();

        $pay_order  = $order_model->payOrderInfo($input);

        if(!empty($pay_order['code'])){

            $this->errorMsg($pay_order['msg']);
        }

        $order_insert = [

            'uniacid'      => $this->_uniacid,

            'pay_type'     => 1,

            'order_code'   => orderCode(),

            'user_id'      => $this->getUserId(),

            'land_id'      => $input['land_id'],

            'pay_price'    => $pay_order['pay_price'],

            'farmer_id'    => $pay_order['land']['farmer_id'],

            'goods_name'   => $pay_order['land']['title'],

            'goods_cover'  => $pay_order['land']['cover'],

            'massif_id'    => $input['massif_id'],

            'spe_id'       => $input['spe_id'],

            'spe_name'     => $pay_order['spe']['spe_name'],

            'area'         => $pay_order['spe']['area'],

            'land_price'   => $pay_order['land_price'],

            'seed_price'   => $pay_order['seed_price'],

            'cycle'        => $input['cycle'],
            //到期时间
            'end_time'     => $input['cycle']*86400+time(),

            'rent_mobile'  => $input['rent_mobile'],

            'rent_user_name'=> $input['rent_user_name'],

            'massif_price' => $pay_order['massif']['price'],

            'massif_title' => $pay_order['massif']['title'],

            'total_massif_price' => $pay_order['total_massif_price'],
            //
            'over_time'  => time()+$this->_config['over_time']*60,

            'send_type'  => $input['send_type'],

        ];

        Db::startTrans();

        $res = $order_model->dataAdd($order_insert);

        if($res==0){

            Db::rollback();

            $this->errorMsg('下单失败');

        }

        $order_id = $order_model->getLastInsID();

        $input['uniacid'] = $this->_uniacid;

        $res = $address_model->orderAddressAdd($input['address_id'],$order_id,$input['send_type'],1,$input);

        if($res==0){

            Db::rollback();

            $this->errorMsg('下单失败');

        }

        if(!empty($pay_order['seed'])){

            $res = $land_seed_model->orderSeedAdd($pay_order['seed'],$order_id);

            if($res==0){

                Db::rollback();

                $this->errorMsg('下单失败');

            }
        }

        Db::commit();
        //如果是0元
        if($order_insert['pay_price']<=0){

            $order_model->orderResult($order_insert['order_code'],$order_insert['order_code']);

            return $this->success(true);
        }
        //余额支付
        if(!empty($input['is_balance'])){

            $user_model = new \app\farm\model\User();

            $user_balance= $user_model->where(['id'=>$this->getUserId()])->value('balance');

            if($user_balance<$order_insert['pay_price']){

                $this->errorMsg('余额不足');
            }

            $order_model->orderResult($order_insert['order_code'],$order_insert['order_code']);

            return $this->success(true);

        }
        //微信支付
        $pay_controller = new \app\shop\controller\IndexWxPay($this->app);
        //支付
        $jsApiParameters= $pay_controller->createWeixinPay($this->payConfig(),$this->getUserInfo()['openid'],$this->_uniacid,"土地订单",['type' => 'Land' , 'out_trade_no' => $order_insert['order_code']],$order_insert['pay_price']);

        $arr['pay_list']= $jsApiParameters;

        return $this->success($arr);

    }


    /**
     * @author chenniang
     * @DataTime: 2021-12-20 10:17
     * @功能说明:土地重新下单
     */
    public function landRePayOrder(){

        $input = $this->_input;

        $order_model = new LandOrder();

        $order_insert = $order_model->dataInfo(['id'=>$input['id']]);

        if($order_insert['pay_type']!=1){

            $this->errorMsg('订单状态错误');
        }
        //余额支付
        if(!empty($input['is_balance'])){

            $user_model = new \app\farm\model\User();

            $user_balance= $user_model->where(['id'=>$this->getUserId()])->value('balance');

            if($user_balance<$order_insert['pay_price']){

                $this->errorMsg('余额不足');
            }

            $order_model->orderResult($order_insert['order_code'],$order_insert['order_code']);

            return $this->success(true);

        }
        //微信支付
        $pay_controller = new \app\shop\controller\IndexWxPay($this->app);
        //支付
        $jsApiParameters= $pay_controller->createWeixinPay($this->payConfig(),$this->getUserInfo()['openid'],$this->_uniacid,"认养订单",['type' => 'Claim' , 'out_trade_no' => $order_insert['order_code']],$order_insert['pay_price']);

        $arr['pay_list']= $jsApiParameters;

        return $this->success($arr);

    }


    /**
     * @author chenniang
     * @DataTime: 2022-01-06 18:03
     * @功能说明:种子列表
     */
    public function seedList(){

        $input = $this->_param;

        $land_text_model = new LandText();

        $obj = $land_text_model->where(['land_id'=>$input['land_id'],'type'=>2])->column('obj_id');

        $dis[] = ['a.status','=',1];

        $dis[] = ['a.id','in',$obj];
        //查询当前季节
        if(!empty($input['season'])){

            $month  = date('m',time());

            $season = ceil($month/3);

            $dis[]  = ['b.season','=',$season];
        }

        $seed_model = new Seed();
        //种子
        $data = $seed_model->indexDataList($dis,$input['sort']);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2022-01-06 18:17
     * @功能说明:种子详情
     */
    public function seedInfo(){

        $input = $this->_param;

        $seed_model = new Seed();

        $dis = [

            'id' => $input['id']
        ];
        //种子
        $data = $seed_model->dataInfo($dis);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2021-12-28 11:26
     * @功能说明:用户下单列表
     */
    public function orderList(){

        $input = $this->_param;

        $order_model  = new LandOrder();

        $farmer_model = new Farmer();

        $user_model   = new User();
        //初始化订单
        $order_model->orderInit();

        $dis[] = ['a.uniacid','=',$this->_uniacid];

        if(!empty($input['pay_type'])){

            $dis[] = ['a.pay_type','=',$input['pay_type']];

        }

        if(!empty($input['order_code'])){

            $dis[] = ['a.order_code','like','%'.$input['order_code'].'%'];

        }

        if(!empty($input['goods_name'])){

            $dis[] = ['a.goods_name','like','%'.$input['goods_name'].'%'];

        }

        if(!empty($input['mobile'])){

            $dis[] = ['b.mobile','like','%'.$input['mobile'].'%'];

        }

        if(!empty($input['farmer_id'])){

            $dis[] = ['a.farmer_id','=',$input['farmer_id']];

        }

        if(!empty($input['start_time'])&&!empty($input['end_time'])){

            $dis[] = ['a.create_time','between',"{$input['start_time']},{$input['end_time']}"];

        }

        $data = $order_model->adminDataList($dis,$input['limit']);

        if(!empty($data['data'])){

            foreach ($data['data'] as &$v){

                $v['farmer_info'] = $farmer_model->dataInfo(['id'=>$v['farmer_id']],'title');

                $v['user_info']   = $user_model->dataInfo(['id'=>$v['user_id']]);

            }
        }

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2021-12-28 11:52
     * @功能说明:用户下单详情
     */
    public function orderInfo(){

        $input = $this->_param;

        $farmer_model = new Farmer();

        $dis = [

            'id' => $input['id']
        ];

        $order_model = new LandOrder();

        $seed_model  = new LandOrderSeed();

        $data = $order_model->dataInfo($dis);
        //农场信息
        $data['farmer_info'] = $farmer_model->dataInfo(['id'=>$data['farmer_id']]);
        //是否可以配送
        $data['can_send'] = $data['pay_type']>1&&$data['end_time']<time()?1:0;
        //种子列表
        $data['seed'] = $seed_model->orderSeed($data['id']);

        $address_model = new OrderAddress();

        $data['address_info'] = $address_model->dataInfo(['order_id'=>$input['id'],'type'=>1]);

        return $this->success($data);

    }





    /**
     * @author chenniang
     * @DataTime: 2022-01-10 13:42
     * @功能说明:
     */
    public function cancelOrder(){

        $input = $this->_input;

        $order_model = new LandOrder();

        $dis = [

            'id' => $input['id']
        ];

        $order = $order_model->dataInfo($dis);

        if($order['pay_type']!=1){

            $this->errorMsg('订单状态错误');
        }

        $res = $order_model->cancelOrder($order);

        if(!empty($res['code'])){

            $this->errorMsg($res['msg']);
        }

        return $this->success($res);

    }


    /**
     * @author chenniang
     * @DataTime: 2022-02-08 13:53
     * @功能说明:申请认养订单发货
     */
    public function sendOrderApply(){

        $input = $this->_input;

        $order_model = new ClaimOrder();

        $farmer_model= new Farmer();

        $config_model= new Config();

        $address_model    = new Address();

        $send_order_model = new SendOrder();

        $order = $order_model->dataInfo(['id'=>$input['order_id']]);

        $times = $send_order_model->where(['order_id'=>$input['order_id'],'type'=>2])->where('pay_time','>',0)->count();

        $farmer= $farmer_model->dataInfo(['id'=>$order['farmer_id']]);

        if(empty($farmer)){

            $this->errorMsg('农场主未找到');
        }

        $send_price = $distance = 0;
        //快递
        if($input['send_type']==2){

            $address = $address_model->dataInfo(['id'=>$input['address_id']]);

            if(empty($address)){

                $this->errorMsg('地址信息未找到');

            }

            $distance   = getdistance($address['lng'],$address['lat'],$farmer['lng'],$farmer['lat']);

            $distance   = round($distance/1000,2);

            $send_price = $config_model->getSendPrice($distance,$this->_uniacid);

        }else{

            $address['user_name'] = $input['user_name'];

            $address['mobile']    = $input['mobile'];

        }

        $order_insert = [

            'uniacid'    => $this->_uniacid,

            'order_id'   => $input['order_id'],

            'user_id'    => $order['user_id'],

            'farmer_id'  => $order['farmer_id'],

            'pay_price'  => $send_price,

            'order_code' => orderCode(),

            'text'       => $input['text'],
            //
            'over_time'  => time()+$this->_config['over_time']*60,

            'type'       => 2,

            'start_time' => $input['start_time'],

            'end_time'   => $input['end_time'],

            'times'      => $times+1,

            'send_type'  => $input['send_type'],

            'address'    => $input['send_type']==2?$address['address'].$address['address_info']:'',

            'user_name'  => $address['user_name'],

            'mobile'     => $address['mobile'],

            'lng'        => $input['send_type']==2?$address['lng']:'',

            'lat'        => $input['send_type']==2?$address['lat']:'',

            'balance'    => !empty($input['is_balance'])?$send_price:0,

        ];

        $res = $send_order_model->dataAdd($order_insert);

        if($res==0){

            $this->errorMsg('申请配送失败');
        }
        //如果是0元
        if($order_insert['pay_price']<=0){

            $send_order_model->orderResult($order_insert['order_code'],$order_insert['order_code']);

            return $this->success(true);
        }
        //余额支付
        if(!empty($input['is_balance'])){

            $user_model = new \app\farm\model\User();

            $user_balance= $user_model->where(['id'=>$this->getUserId()])->value('balance');

            if($user_balance<$order_insert['pay_price']){

                $this->errorMsg('余额不足');
            }

            $send_order_model->orderResult($order_insert['order_code'],$order_insert['order_code']);

            return $this->success(true);

        }
        //微信支付
        $pay_controller = new \app\shop\controller\IndexWxPay($this->app);
        //支付
        $jsApiParameters= $pay_controller->createWeixinPay($this->payConfig(),$this->getUserInfo()['openid'],$this->_uniacid,"认养配送订单",['type' => 'ClaimSend' , 'out_trade_no' => $order_insert['order_code']],$order_insert['pay_price']);

        $arr['pay_list']= $jsApiParameters;

        return $this->success($arr);

    }




    /**
     * @author chenniang
     * @DataTime: 2022-02-08 15:23
     * @功能说明:配送订单下单详情
     */
    public function sendOrderPayInfo(){

        $input  = $this->_param;

        $order_model = new LandOrder();

        $farmer_model= new Farmer();

        $config_model= new Config();

        $address_model = new Address();

        $order = $order_model->dataInfo(['id'=>$input['order_id']]);

        $farmer= $farmer_model->dataInfo(['id'=>$order['farmer_id']]);

        if(empty($farmer)){

            $this->errorMsg('农场主未找到');
        }

        $address = $address_model->dataInfo(['id'=>$input['address_id']]);

        if(empty($address)){

            $this->errorMsg('地址信息未找到');

        }
        $distance   = getdistance($address['lng'],$address['lat'],$farmer['lng'],$farmer['lat']);

        $distance   = round($distance/1000,2);

        $send_price = $config_model->getSendPrice($distance,$this->_uniacid);

        $data['send_price'] = $send_price;

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2022-02-08 17:14
     * @功能说明:配送订单列表
     */
    public function userSendOrderList(){

        $input = $this->_param;

        $send_order_model = new SendOrder();

        $data = $send_order_model->orderSendOrder($input['land_order_id'],2,$input['limit']);

        return $this->success($data);

    }

    /**
     * @author chenniang
     * @DataTime: 2022-02-09 14:00
     * @功能说明:配送订单详情
     */
    public function sendOrderInfo()
    {

        $input = $this->_param;

        $send_order_model = new SendOrder();

        $claim_order_model = new LandOrder();

        $send_order = $send_order_model->dataInfo(['id' => $input['id']]);

        $send_order['create_time'] = date('Y-m-d H:i:s', $send_order['create_time']);

        $send_order['time_text'] = date('Y-m-d H:i', $send_order['start_time']) . '~' . date('H:i', $send_order['end_time']);

        $send_order['pay_time'] = $send_order['pay_time'] > 0 ? date('Y-m-d H:i:s', $send_order['pay_time']) : 0;

        $send_order['send_time'] = $send_order['send_time'] > 0 ? date('Y-m-d H:i:s', $send_order['send_time']) : 0;

        $send_order['receiving_time'] = $send_order['receiving_time'] > 0 ? date('Y-m-d H:i:s', $send_order['receiving_time']) : 0;

        $send_order['refund_time'] = $send_order['refund_time'] > 0 ? date('Y-m-d H:i:s', $send_order['refund_time']) : 0;

        $send_order['claim_order'] = $claim_order_model->dataInfo(['id' => $send_order['order_id']]);

        return $this->success($send_order);

    }



    /**
     * @author chenniang
     * @DataTime: 2022-02-08 17:57
     * @功能说明:配送订单退款
     */
    public function sendOrderRefund(){

        $input = $this->_input;

        $send_order_model = new SendOrder();

        $send_order = $send_order_model->dataInfo(['id'=>$input['id']]);

        if(empty($send_order)){

            $this->errorMsg('订单未找到');
        }

        if($send_order['pay_type']!=2){

            $this->errorMsg('订单状态错误');
        }

        Db::startTrans();

        if($send_order['send_type']==2&&$send_order['pay_price']>0&&$send_order['balance']<=0){
            //微信退款
            $response = orderRefundApi($this->payConfig($this->_uniacid),$send_order['pay_price'],$send_order['pay_price'],$send_order['transaction_id']);

        }else{
            //余额或者自提或者0元
            $response[ 'return_code' ] = 'SUCCESS';

            $response[ 'result_code' ] = 'SUCCESS';
        }
        //余额退款
        if($send_order['balance']>0){

            $water_model = new BalanceWater();

            $res = $water_model->addWater($send_order,4,1);

            if($res==0){

                Db::rollback();

                $this->errorMsg('退款失败2');
            }

        }
        //增加财务流水
        $fin_water_model = new FinanceWater();

        $res = $fin_water_model->addWater($input['id'],13,1,1);

        if($res==0){

            Db::rollback();

            $this->errorMsg('退款失败1');
        }

        $res = $fin_water_model->dataUpdate(['order_id'=>$send_order['id'],'type'=>14],['cash_status'=>-1]);

        if($res==0){

            Db::rollback();

            $this->errorMsg('退款失败3');
        }
        //如果退款成功修改一下状态
        if ( isset( $response[ 'return_code' ] ) && isset( $response[ 'result_code' ] ) && $response[ 'return_code' ] == 'SUCCESS' && $response[ 'result_code' ] == 'SUCCESS' ) {

            $response['out_refund_no'] = !empty($response['out_refund_no'])?$response['out_refund_no']:$send_order['order_code'];

            $send_order_model->dataUpdate(['id'=>$send_order['id']],['refund_code'=>$response['out_refund_no'],'refund_time'=>time(),'pay_type'=>-1,'refund'=>1]);

        }else {

            Db::rollback();
            //失败就报错
            $discption = !empty($response['err_code_des'])?$response['err_code_des']:$response['return_msg'];

            $this->errorMsg($discption);

        }
        Db::commit();

        return $this->success(true);

    }


    /**
     * @author chenniang
     * @DataTime: 2022-02-09 10:24
     * @功能说明:配送订单收货
     */
    public function sendOrderReceiving(){

        $input = $this->_input;

        $send_order_model = new SendOrder();

        $send_order = $send_order_model->dataInfo(['id'=>$input['id']]);

        if(empty($send_order)){

            $this->errorMsg('订单未找到');
        }

        if($send_order['pay_type']!=3){

            $this->errorMsg('订单状态错误');
        }

        $res = $send_order_model->sendOrderReceiving($send_order);

        if(!empty($res['code'])){

            $this->errorMsg($res['msg']);
        }

        return $this->success(true);

    }



    /**
     * @author chenniang
     * @DataTime: 2021-12-10 17:51
     * @功能说明:土地列表
     */
    public function landList(){

        $input = $this->_param;

        if(!empty($input['title'])){

            $dis[] = ['title','like','%'.$input['title'].'%'];
        }

        $dis[] = ['uniacid','=',$this->_uniacid];

        if(isset($input['status'])){

            $dis[] = ['status','=',$input['status']];

        }else{

            $dis[] = ['status','>',-1];
        }

        if(!empty($input['farmer_id'])){

            $dis[] = ['farmer_id','=',$input['farmer_id']];
        }

        $data = $this->model->dataList($dis,$input['limit']);

        if(!empty($data['data'])){

            $farmer_model = new Farmer();

            foreach ($data['data'] as &$v){

                $v['farmer_name'] = $farmer_model->where(['id'=>$v['farmer_id']])->value('title');

                $cate_name = $this->cate_model->where('id','in',$v['cate_id'])->column('title');

                $v['cate_name'] = implode(',',$cate_name);

            }
        }

        $arr = [

            0 => 'off_num',

            1 => 'on_num',
        ];

        foreach ($arr as $key => $value){

            $dis = [

                'uniacid' => $this->_uniacid,

                'status'  => $key
            ];

            $data[$value] = $this->model->where($dis)->count();

        }

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2021-12-10 18:05
     * @功能说明:添加土地
     */
    public function landAdd(){

        $input = $this->_input;

        $input['uniacid'] = $this->_uniacid;

        $res = $this->model->dataAdd($input);

        return $this->success($res);

    }



    /**
     * @author chenniang
     * @DataTime: 2021-12-10 18:05
     * @功能说明:编辑土地
     */
    public function landUpdate(){

        $input = $this->_input;

        $dis = [

            'id' => $input['id']

        ];

        $input['uniacid'] = $this->_uniacid;

        $res = $this->model->dataUpdate($dis,$input);

        return $this->success($res);

    }


    /**
     * @author chenniang
     * @DataTime: 2021-12-10 18:05
     * @功能说明:编辑土地
     */
    public function landStatusUpdate(){

        $input = $this->_input;

        $dis = [

            'id' => $input['id']

        ];

        $res = $this->model->where($dis)->update($input);

        return $this->success($res);

    }



    /**
     * @author chenniang
     * @DataTime: 2021-12-10 18:05
     * @功能说明:土地详情
     */
    public function landInfo(){

        $input = $this->_param;

        $dis = [

            'id' => $input['id']

        ];

        $data = $this->model->landInfo($dis);

        $data['text'] = html_entity_decode($data['text']);

        $data['massif']  = array_values(array_column($data['massif'],'id'));

        $data['monitor'] = array_values(array_column($data['monitor'],'id'));

        $data['seed']    = array_values(array_column($data['seed'],'id'));

        $freightTemplate_model = new FreightTemplate();

        $res['send_template_type'] = $freightTemplate_model->where(['id'=>$data['send_tmpl_id']])->value('type');

        return $this->success($data);

    }






}
